[jQuey] How select an element by class name, previously loaded in DOM

Posted by Mattia on Stack Overflow See other posts from Stack Overflow or by Mattia
Published on 2010-04-04T21:04:58Z Indexed on 2010/04/04 21:13 UTC
Read the original article Hit count: 274

Filed under:

I write a simple piece of code that creates a div and assign it a class name:

$('#create_div').click( 
function() {    
  div = $("<div>").addClass("myClass");
  $("body").append(div); 
} 
);

Ok: after "create_div" button is fired the function appends the new div to body container.

Now... : How to select the new element created ? How do I reach it? I have tried:

$('.myClass').click( 
function() {    
  // do something 
} 
);

but it doesn't works. Thanks for the help!

© Stack Overflow or respective owner

Related posts about jQuery